package com.wdc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wdc.entity.BookEntity;
import com.wdc.entity.Borrowuser;
import com.wdc.service.BorrowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/borrow")
@Slf4j
public class BorrowController {

    @Autowired
    private BorrowService borrowService;


    @GetMapping("/page")
    public Page<Borrowuser> findPage(@RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize) {


        QueryWrapper<BookEntity> queryWrapper = new QueryWrapper<>();

        queryWrapper.orderByDesc("id");
        return borrowService.page(new Page<>(pageNum,pageSize));
    }

    @PostMapping("/save")
    public Boolean save(@RequestBody Borrowuser borrowuser) {
        log.info("book : {}", borrowuser.toString());
        return borrowService.saveOrUpdate(borrowuser);
    }


}
